package cn.itcast.bos.service.transit.imp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.take_delivery.WayBillDao;
import cn.itcast.bos.dao.transit.SingInfoDao;
import cn.itcast.bos.dao.transit.TransitInfoDao;
import cn.itcast.bos.domain.transit.SignInfo;
import cn.itcast.bos.domain.transit.TransitInfo;
import cn.itcast.bos.index.WayBillIndexRepository;
import cn.itcast.bos.service.transit.SignInfoService;

@Service
@Transactional
public class SignInfoServiceImp implements SignInfoService {

	@Autowired
	private SingInfoDao singInfoDao;
	@Autowired
	private TransitInfoDao transitDao;
	@Autowired
	private WayBillIndexRepository wayBillDao;
	
	@Override
	public void save(String transitInfoId, SignInfo sig) {
		//保存签收录入信息
		singInfoDao.save(sig);
		//关联运输流程
		TransitInfo transitInfo =transitDao.findOne(Integer.parseInt(transitInfoId));
		transitInfo.setSignInfo(sig);
		
		//更改状态
		if(sig.getSignType().equals("正常")){
			//正常签收
			transitInfo.setStatus("正常签收");
			//更改运单状态
			transitInfo.getWayBill().setSignStatus(3);
			//更改索引库
			wayBillDao.save(transitInfo.getWayBill());
		}else{
			//异常
			transitInfo.setStatus("异常");
			//更改运单状态
			transitInfo.getWayBill().setSignStatus(4);
			//更改索引库
			wayBillDao.save(transitInfo.getWayBill());
			
		}
	}

}
